package com.fish.account.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fish.account.po.Account;
import com.fish.common.constant.QueryPage;
import com.fish.common.dao.BaseIbatisDao;
import com.fish.passport.po.PassCode;


public class AccountDAO extends BaseIbatisDao {
	private static final Log loger = LogFactory.getLog(AccountDAO.class);
	public AccountDAO() {
		super();
	}

	/**
	 * 根据主键查询
	 * 
	 * @update zhangzhenhua 2010-9-20
	 */
	public Account queryAccountByPrimaryKey(Account account) {
		loger.debug("selectByPrimaryKey id is :" + account.getAccountId());
		return (Account) this.getSqlMapClientTemplate().queryForObject("ACCOUNT.selectByPrimaryKey", account);
	}

	/**
	 * 模糊查询
	 * 
	 * @update zhangzhenhua 2010-9-20
	 */
	@SuppressWarnings("unchecked")
	public List<Account> queryAccountByObject(Account account) {
		return (ArrayList<Account>) this.getSqlMapClientTemplate().queryForList("ACCOUNT.queryBySettlement",account);
	}
	
	/**
	 * 按bankId查询
	 * 
	 * @update zhangzhenhua 2010-9-20
	 */
	@SuppressWarnings("unchecked")
	public ArrayList<Account> queryAccountByBankId(Account account) {
		return (ArrayList<Account>) this.getSqlMapClientTemplate().queryForList("ACCOUNT.queryAccountByBankId",account);
	}

	/**
	 * 添加
	 * 
	 * @update zhangzhenhua 2010-9-20
	 */
	public void insertAccount(Account account) {
		this.getSqlMapClientTemplate().insert("ACCOUNT.insert", account);
	}
	
	/**
	 * 修改
	 * 
	 * @update zhangzhenhua 2010-9-20
	 */
	public void updateAccount(Account account) {
		this.getSqlMapClientTemplate().update("ACCOUNT.updateByPrimaryKeySelective", account);
	}
	
	public Long queryAccountCountByObject(Account account){
		return  (Long) this.getSqlMapClientTemplate().queryForObject("ACCOUNT.countAccountWithPaging", account);
	}
	
	public  List<Account> queryAccountObject(Account account,QueryPage queryPage){
		account.setBeginItem(queryPage.getBeginItem());
		account.setEndItem(queryPage.getPageSize());
		return (List<Account>) this.getSqlMapClientTemplate().queryForList("ACCOUNT.selectAccountWithPaging", account);
	}
}